package com.lkd.controller;

import com.lkd.result.Result;
import com.lkd.service.StatisticsService;
import com.lkd.vo.TaskReportInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

//统计分析
@RestController
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    //订单统计
    @GetMapping("/api/order-service/report/orderCount")
    public Result orderCount(
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end) {
        Integer orderCount = statisticsService.orderCount(start, end);
        return Result.success(orderCount);
    }

    //销售额统计
    @GetMapping("/api/order-service/report/orderAmount")
    public Result orderAmount(
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end) {
        Double orderAmount = statisticsService.orderAmount(start, end);
        return Result.success(orderAmount);
    }

    //点位数量
    @GetMapping("/api/vm-service/node/count")
    public Result nodeCount() {
        Integer nodeCount = statisticsService.nodeCount();
        return Result.success(nodeCount);
    }

    //合作商数量
    @GetMapping("/api/user-service/partner/count")
    public Result partnerCount() {
        Integer partnerCount = statisticsService.partnerCount();
        return Result.success(partnerCount);
    }

    //工单统计
    @GetMapping("/api/task-service/task/taskReportInfo/{start}/{end}")
    public Result taskReportInfo(
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end) {
        List<TaskReportInfoVo> list = statisticsService.taskReportInfo(start, end);
        return Result.success(list);
    }
}
